package com.example.sharedpreferencedemo;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }

    public void writeInfo(View view) {
        EditText userNameEdit = (EditText)findViewById(R.id.edit_user_name);
        EditText passwordEdit = (EditText)findViewById(R.id.edit_password);
        String userName = userNameEdit.getText().toString();
        String password = passwordEdit.getText().toString();
        UserInfo userInfo = new UserInfo(userName, password);
        SPUserInfo.put(userInfo);
    }

    public void readInfo(View view) {
        TextView userNameText = (TextView)findViewById(R.id.text_user_name);
        TextView passwordText = (TextView)findViewById(R.id.text_password);
        UserInfo userInfo = SPUserInfo.get();
        userNameText.setText(userInfo.getUserName());
        passwordText.setText(userInfo.getPassword());
    }
}
